package API.AboutTime.SimpleDateFormatAPI.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateToAnotherString {
    public static void main(String[] args) {
        String dateStr = "2006-01-01";
        //定义两个SimpleDateFormat对象，且格式不同，用于转换日期格式
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
        //转换为Date再转换为新格式日期字符串并输出
        try {
            Date date = sdf1.parse(dateStr);
            System.out.println(sdf2.format(date));
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
